package com.kgc.personprovider.controller;

import com.kgc.basic.util.ResponseMsg;
import com.kgc.personcommon.pojo.Permission;
import com.kgc.personcommon.remote.PermissionRemote;
import com.kgc.personprovider.service.PermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import reactor.core.publisher.Mono;

import java.util.Map;

@Controller
public class PermissionController implements PermissionRemote {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PermissionService permissionService;

    @Override
    public ResponseMsg getPermPage(Map<String, Object> map) {
        logger.info("PermissionController getPermPage map={}", map);
        ResponseMsg responseMsg =permissionService.getByPage(map);
        logger.debug("permissionService getPermPage map={}", map+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg addPerm(Permission permission) {
        logger.info("PermissionController addPerm permission={}", permission);
        ResponseMsg responseMsg = permissionService.add(permission);
        logger.debug("permissionService addPerm permission={}", permission+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg updatePerm(Permission permission) {
        logger.info("PermissionController updatePerm permission={}", permission);
        ResponseMsg responseMsg = permissionService.update(permission);
        logger.debug("permissionService updatePerm permission={}", permission+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg delPerm(String id) {
        logger.info("PermissionController delPerm id={}", id);
        ResponseMsg responseMsg = permissionService.delete(id);
        logger.debug("permissionService delPerm id={}", id+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg getPermById(String id) {
        logger.info("PermissionController getPermById id={}", id);
        ResponseMsg responseMsg = permissionService.getById(id);
        logger.debug("permissionService getPermById id={}", id+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public ResponseMsg getAllPerm(Map<String, Object> map) {
        logger.info("PermissionController getAllPerm map={}", map);
        ResponseMsg responseMsg = permissionService.getAll(map);
        logger.debug("permissionService getAllPerm map={}", map+",responseMsg="+responseMsg);
        return responseMsg;
    }

    @Override
    public Mono<Permission> getPermissionForPath(String path) {
        logger.info("PermissionController getPermissionForPath path={}", path);
        Permission permission = permissionService.getPermByPath(path);
        logger.debug("permissionService getPermissionForPath path={}", path+",responseMsg="+permission);
        Mono<Permission> mono = Mono.just(permission);
        return mono;
    }
}
